<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>竣工验收记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/templates/act/process-xl.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form searchForm" action="">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">所在区域：</label>
            <div class="layui-input-inline" style="width: 120px;">
                <select lay-search  name="cityNum" id="cityNum" autocomplete="off" class="layui-input" lay-filter="cityChange">
                    <option value="">请选择</option>
                    <option value="130100">石家庄市</option>
                    <option value="130200">唐山市</option>
                    <option value="130300">秦皇岛市</option>
                    <option value="130400">邯郸市</option>
                    <option value="130500">邢台市</option>
                    <option value="130600">保定市</option>
                    <option value="130700">张家口市</option>
                    <option value="130800">承德市</option>
                    <option value="130900">沧州市</option>
                    <option value="131000">廊坊市</option>
                    <option value="131100">衡水市</option>
                </select>
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 120px;">
                <select lay-search  name="countyNum" id="countyNum" autocomplete="off" class="layui-input">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">项目名称：</label>
            <div class="layui-input-inline">
                <input name="prjName" id="prjName" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <button class="layui-btn" lay-submit lay-filter="formDemo" id="formSubmit">查询</button>
        <button class="layui-btn" lay-submit lay-filter="formClear">清空</button>
    </div>

    <div class="layui-form-item" style="margin-bottom: 0px;">
        <div class="layui-inline">
            <label class="layui-form-label">申请状态：</label>
            <div class="layui-input-inline" style="width: 780px;">
                <input type="checkbox" name="aStatus" value="0" title="未申请" lay-filter="aStatus">
                <input type="checkbox" name="aStatus" value="1,2,3,4,5,6" title="进行中" lay-filter="aStatus">
                <input type="checkbox" name="aStatus" value="7" title="已完成" lay-filter="aStatus">
                <input type="checkbox" name="aStatus" value="10,11" title="已拒绝" lay-filter="aStatus">
                <input type="hidden" name="status" id="status">
            </div>
        </div>
    </div>
</form>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="toolbarOrg">
    {{# if(org && org.orgType=='1'){ }}
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-normal layui-btn-sm" lay-event="add">竣工验收申请</button>
    </div>
    {{# } }}
</script>

<script type="text/html" id="detailBtn">
    <a class="layui-btn layui-btn layui-btn-xs" lay-event="completionDetail">查看</a>
</script>

<script type="text/html" id="gcjgysbgBtn">
    {{# if(d.status==7){ }}
    <a class="layui-btn layui-btn layui-btn-xs" lay-event="gcjgysbg">下载</a>
    {{# } }}
</script>

<script type="text/javascript" src="/templates/user/address.js"></script>
<script type="text/javascript" src="/lib/layui/lay/modules/laydate.js"></script>
<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    var org;
    var user;
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'laydate','element', 'process'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var configureCom = layui.configureCom;
        var laydate = layui.laydate;
        var form=layui.form;
        var element = layui.element;
        var iframeId = configureCom.GetQueryString('iframeId');
        var process = layui.process;
        org = sessionFun.get(configure.SESSION_LOGIN_ORG_DATA);
        user = sessionFun.get(configure.SESSION_LOGIN_USER_DATA);
        var token = sessionFun.get(configure.SESSION_TOKEN) ? sessionFun.get(configure.SESSION_TOKEN).token : '';


        var cols = [[
            {field: 'buildProjectLeaderId', title: '所属区域', templet: function (d) {
                //区划code转中文
                if(d.provinceNum && d.cityNum && d.countyNum){
                    return convertAddressCode(d.provinceNum, d.cityNum, d.countyNum);
                }else{
                    return d.provinceNum+'-'+d.cityNum+'-'+d.countyNum;
                }
            }},
            {field: 'prjName', title: '项目名称'},
            {field: 'unitPrjName', title: '单位工程名称'},
            {field: 'aptDate', title: '验收日期'},
            {field: 'site', title: '验收地点'},
            {field: 'status', title: '状态',templet:function(d){
                if(0==d.status){
                    return '未申请'
                }else if(1==d.status){
                    return '监督条件审批中'
                }else if(2==d.status){
                    return '监督中'
                }else if(3==d.status){
                    return '编写竣工验收情况中'
                }else if(4==d.status){
                    return '编写质量监督报告中'
                }else if(5==d.status){
                    return '主管部门审批盖章中'
                }else if(6==d.status){
                    return '编写竣工报告中'
                }else if(7==d.status){
                    return '已完成'
                }else if(10==d.status){
                    return '条件核查不符'
                }else if(11==d.status){
                    return '竣工验收监督不符合'
                }else{
                    return '';
                }
            }},
            {fixed: 'right', title: '详情', toolbar: '#detailBtn'},
            {fixed: 'right', title: '工程竣工验收报告', toolbar: '#gcjgysbgBtn'}
        ]];
        configureCom.tableRender(configure.COMPLETION_LIST_API, {}, cols, 'dataList', 10, '', 'toolbarOrg');

        //头工具栏事件
        table.on('toolbar(dataList)', function (obj) {
            sessionFun.remove(configure.COMPLETION_ROW_DATA);
            switch (obj.event) {
                case 'add':
                    //清缓存
                    sessionFun.set('cptAcceptanceId', null);
                    sessionFun.set(configure.SESSION_PROC_WAIT_DEAL_ROW_DATA, null);
                    editItem('竣工验收申请', configure.COMPLETION_PROCESS_HTML);
                    break;
            }
        });

        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.COMPLETION_ROW_DATA, data);
            if (obj.event === 'completionDetail') {
                //清缓存
                sessionFun.set('cptAcceptanceId', null);
                sessionFun.set(configure.SESSION_PROC_WAIT_DEAL_ROW_DATA, null);

                editItem('竣工验收申请', configure.COMPLETION_PROCESS_HTML);
//                top.layer.open({
//                    type: 2,
//                    title: '中止施工申请详情',
//                    area: configureCom.Psize1,
//                    content: configureCom.nocache(configure.PAUSE_DETAIL_HTML),
//                    success: function (layero, index) {
//                        top.layer.full(index);
//                    }
//                });

            } else if (obj.event === 'gcysjdtzsBtn') {
                alert('gcysjdtzsBtn');
//                top.layer.open({
//                    type: 2,
//                    title: '建设工程中止施工申请书',
//                    area: configureCom.Psize1,
//                    content: configureCom.nocache(configure.PAUSE_DETAIL_HTML),
//                    success: function (layero, index) {
////                        top.layer.full(index);
//                    }
//                });
            } else if (obj.event === 'gcjgysbg') {
                window.open("/api/cpt/acceptance/report/gcjgysbgFile/download?token="+token + "&id="+data.id +"&rebuildFlag=0");
            }
        });


        //开始时间-结束时间
        var start = laydate.render({
            elem: '#startDate',
            done:function(value,date){
                endMax = end.config.max;
                end.config.min = date;
                end.config.min.month = date.month -1;
            }
        });
        var end = laydate.render({
            elem: '#endDate',
            done:function(value,date){
                if($.trim(value) == ''){
                    var curDate = new Date();
                    date = {'date': curDate.getDate(), 'month': curDate.getMonth()+1, 'year': curDate.getFullYear()};
                }
                start.config.max = date;
                start.config.max.month = date.month -1;
            }
        });

        //监听市区级联
        form.on('select(cityChange)', function(data){
            var val=data.value;
            if(val){
                //加载区
                $("#countyNum").empty();
                $("#countyNum").append('<option value="">请选择</option>');
                var countyList = findCountyListByCity('130000',val);
                //遍历下拉查询返回值，并拼接到下拉框内
                $.each(countyList, function(idx, obj) {
                    $("#countyNum").append('<option value="'+obj.areaCode+'">'+obj.areaName+'</option>');
                });
            }else{
                //清空区
                $("#countyNum").empty();
                $("#countyNum").append('<option value="">请选择</option>');
            }
            //重新渲染form表单  否则动态option不生效
            form.render();
        });


        //监听问题状态
        form.on('checkbox(aStatus)', function(data){
            var aStatus = '';
            // 遍历name=aType 的多选框
            $("input:checkbox[name='aStatus']:checked").each(function() {
                aStatus = aStatus+ $(this).val() + ',';
            });
            if(aStatus){
                aStatus = aStatus.substr(0,aStatus.length-1)
            }
            $("#status").val(aStatus);
        });

        //监听搜索
        configureCom.tableSearch();

        //新增或修改字典详情
        function editItem(title, url) {
            top.layer.open({
                type: 2,
                title: title,
                area: configureCom.Psize1,
                content: configureCom.nocache(url),
                success: function (layero, index) {
                    top.layer.full(index);
                },
                end: function(){
                    tableRefresh();
                }
            });
//            top.layer.open({
//                type: 2,
//                title: title,
//                area: configureCom.Psize1,
//                content: configureCom.nocache(configure.PAUSE_DETAIL_HTML),
//                btn: ['保存'],
//                yes: function (index, layero) {
//                    var iframeWin = top.window.frames['layui-layer-iframe' + index]; //得到iframe页的窗口对
//                    var data = iframeWin.getData();
//                    console.log(data);
//                    configureCom.postDataAjax(url, data).then(function (res) {
//                        if (res.code == 0) {
//                            top.layer.close(index);
//                            top.layer.msg('保存成功！');
//                            configureCom.tableReload(true);
//                        } else {
//                            top.layer.alert('保存失败！');
//                        }
//                    });
//                }
//            });
        }

    });

    /**
     * 根据省市区划编码查找区及集合
     * @param provinceNum
     * @param cityNum
     * @returns {
     */
    function findCountyListByCity(provinceNum, cityNum){
        var mallAreaList = [];
        //查找省
        for(i = 0,len=address.length; i < len; i++) {
            var province = address[i];
            if(provinceNum==province.provinceCode){
                var mallCityList = province.mallCityList;
                //查找区
                for(j = 0,len=mallCityList.length; j < len; j++) {
                    var city = mallCityList[j];
                    if(cityNum==city.cityCode){
                        mallAreaList = city.mallAreaList;
                        break;
                    }
                }
                break;
            }
        }
        return mallAreaList;
    }

    /**
     * 根据区划编码转换区划名称
     * @param provinceNum
     * @param cityNum
     * @param countyNum
     * @returns {string}
     */
    function convertAddressCode(provinceNum, cityNum, countyNum){
        var provinceName = '';
        var cityName = '';
        var countyName = '';
        //查找省
        for(i = 0,len=address.length; i < len; i++) {
            var province = address[i];
            if(provinceNum==province.provinceCode){
                provinceName = province.provinceName;
                mallCityList = province.mallCityList;
                //查找区
                for(j = 0,len=mallCityList.length; j < len; j++) {
                    var city = mallCityList[j];
                    if(cityNum==city.cityCode){
                        cityName = city.cityName;
                        mallAreaList = city.mallAreaList;
                        //查找区
                        for(k = 0,len=mallAreaList.length; k < len; k++) {
                            var county = mallAreaList[k];
                            if(countyNum==county.areaCode){
                                countyName = county.areaName;
                                break;
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }
        return cityName+'-'+countyName;
    }

    function tableRefresh(){
        document.getElementById("formSubmit").click();
    }
</script>
</body>
</html>